package com.bsoft.gol.hcb.controller;

import com.bsoft.gol.hcb.bean.request.HealthRecordsListReq;
import com.bsoft.gol.hcb.bean.response.HealthRecordsListResp;
import com.alibaba.fastjson.JSONObject;
import com.bsoft.gol.hcb.service.HealthRecordsService;
import hcn.util.BaseResponse;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @Author zj
 * @Date 2020/12/15 13:14
 * @Description
 */
@Controller
@RequestMapping(value = "/api/auth/healthRecords")
public class HealthRecordsController {
    private final static Logger log = LoggerFactory.getLogger(HealthRecordsController.class);

    @Autowired
    private HealthRecordsService healthRecordsService;

    /**
     * @Description 健康记录查询
     */
    @RequestMapping("healthRecordsList")
    @ResponseBody
    public BaseResponse<List<HealthRecordsListResp>> healthRecordsList(@RequestBody HealthRecordsListReq req) {
        BaseResponse<List<HealthRecordsListResp>> baseResponse = new BaseResponse<>();

        try {
            List<HealthRecordsListResp> healthRecordsListRespList = healthRecordsService.healthRecordsList(req);
            baseResponse.setData(healthRecordsListRespList);
        }catch (Exception e){
            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage(e.getMessage());
        }

        log.info("Out method healthRecordsList, resp:{}", JSONObject.toJSONString(baseResponse));
        return baseResponse;
    }

}
